using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Threading.Tasks;
using Newtonsoft.Json;
using System.Net.Http;

namespace MeteoSwiss.Services
{
	public partial class Person : INotifyPropertyChanged
	{	
		private string firstName;
		[JsonProperty("firstName", Required = Required.Default)]
		public string FirstName
		{
			get { return firstName; }
			set 
			{
				if (value != firstName)
				{
					firstName = value; 
					OnPropertyChanged("FirstName");
				}
			}
		}
		
		private string lastName;
		[JsonProperty("lastName", Required = Required.Always)]
		public string LastName
		{
			get { return lastName; }
			set 
			{
				if (value != lastName)
				{
					lastName = value; 
					OnPropertyChanged("LastName");
				}
			}
		}
		
	
		public string ToJson() 
		{
			return JsonConvert.SerializeObject(this);
		}
	
		public static Person FromJson(string json)
		{
			return JsonConvert.DeserializeObject<Person>(json);
		}
		
		public event PropertyChangedEventHandler PropertyChanged;
	
		protected virtual void OnPropertyChanged(string propertyName = null)
		{
			PropertyChangedEventHandler handler = PropertyChanged;
			if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
		}
	}
	
	public partial class SavePersonRequest : INotifyPropertyChanged
	{	
		private string firstName;
		[JsonProperty("firstName", Required = Required.Default)]
		public string FirstName
		{
			get { return firstName; }
			set 
			{
				if (value != firstName)
				{
					firstName = value; 
					OnPropertyChanged("FirstName");
				}
			}
		}
		
		private string lastName;
		[JsonProperty("lastName", Required = Required.Always)]
		public string LastName
		{
			get { return lastName; }
			set 
			{
				if (value != lastName)
				{
					lastName = value; 
					OnPropertyChanged("LastName");
				}
			}
		}
		
	
		public string ToJson() 
		{
			return JsonConvert.SerializeObject(this);
		}
	
		public static SavePersonRequest FromJson(string json)
		{
			return JsonConvert.DeserializeObject<SavePersonRequest>(json);
		}
		
		public event PropertyChangedEventHandler PropertyChanged;
	
		protected virtual void OnPropertyChanged(string propertyName = null)
		{
			PropertyChangedEventHandler handler = PropertyChanged;
			if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
		}
	}
	
	public partial class SavePersonResponse : INotifyPropertyChanged
	{	
		private string firstName;
		[JsonProperty("firstName", Required = Required.Default)]
		public string FirstName
		{
			get { return firstName; }
			set 
			{
				if (value != firstName)
				{
					firstName = value; 
					OnPropertyChanged("FirstName");
				}
			}
		}
		
		private string lastName;
		[JsonProperty("lastName", Required = Required.Always)]
		public string LastName
		{
			get { return lastName; }
			set 
			{
				if (value != lastName)
				{
					lastName = value; 
					OnPropertyChanged("LastName");
				}
			}
		}
		
	
		public string ToJson() 
		{
			return JsonConvert.SerializeObject(this);
		}
	
		public static SavePersonResponse FromJson(string json)
		{
			return JsonConvert.DeserializeObject<SavePersonResponse>(json);
		}
		
		public event PropertyChangedEventHandler PropertyChanged;
	
		protected virtual void OnPropertyChanged(string propertyName = null)
		{
			PropertyChangedEventHandler handler = PropertyChanged;
			if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
		}
	}
	
	public partial class OverviewRegionForecast : INotifyPropertyChanged
	{	
		private long date;
		[JsonProperty("date", Required = Required.Always)]
		public long Date
		{
			get { return date; }
			set 
			{
				if (value != date)
				{
					date = value; 
					OnPropertyChanged("Date");
				}
			}
		}
		
		private long? icon;
		[JsonProperty("icon", Required = Required.Default)]
		public long? Icon
		{
			get { return icon; }
			set 
			{
				if (value != icon)
				{
					icon = value; 
					OnPropertyChanged("Icon");
				}
			}
		}
		
		private long temperatureMin;
		[JsonProperty("temperatureMin", Required = Required.Always)]
		public long TemperatureMin
		{
			get { return temperatureMin; }
			set 
			{
				if (value != temperatureMin)
				{
					temperatureMin = value; 
					OnPropertyChanged("TemperatureMin");
				}
			}
		}
		
		private long temperatureMax;
		[JsonProperty("temperatureMax", Required = Required.Always)]
		public long TemperatureMax
		{
			get { return temperatureMax; }
			set 
			{
				if (value != temperatureMax)
				{
					temperatureMax = value; 
					OnPropertyChanged("TemperatureMax");
				}
			}
		}
		
	
		public string ToJson() 
		{
			return JsonConvert.SerializeObject(this);
		}
	
		public static OverviewRegionForecast FromJson(string json)
		{
			return JsonConvert.DeserializeObject<OverviewRegionForecast>(json);
		}
		
		public event PropertyChangedEventHandler PropertyChanged;
	
		protected virtual void OnPropertyChanged(string propertyName = null)
		{
			PropertyChangedEventHandler handler = PropertyChanged;
			if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
		}
	}
	
	public partial class Overview : INotifyPropertyChanged
	{	
		private long plz;
		[JsonProperty("plz", Required = Required.Always)]
		public long Plz
		{
			get { return plz; }
			set 
			{
				if (value != plz)
				{
					plz = value; 
					OnPropertyChanged("Plz");
				}
			}
		}
		
		private ObservableCollection<OverviewRegionForecast> regionForecast;
		[JsonProperty("regionForecast", Required = Required.Always)]
		public ObservableCollection<OverviewRegionForecast> RegionForecast
		{
			get { return regionForecast; }
			set 
			{
				if (value != regionForecast)
				{
					regionForecast = value; 
					OnPropertyChanged("RegionForecast");
				}
			}
		}
		
	
		public string ToJson() 
		{
			return JsonConvert.SerializeObject(this);
		}
	
		public static Overview FromJson(string json)
		{
			return JsonConvert.DeserializeObject<Overview>(json);
		}
		
		public event PropertyChangedEventHandler PropertyChanged;
	
		protected virtual void OnPropertyChanged(string propertyName = null)
		{
			PropertyChangedEventHandler handler = PropertyChanged;
			if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
		}
	}
	
	public partial class MeteoServiceClient
	{
		public string BaseUrl { get; private set; }
	
		public MeteoServiceClient(string baseUrl)
		{
			BaseUrl = baseUrl; 
		}
	
		public async Task<SavePersonResponse> SavePersonAsync(long _person, SavePersonRequest savePersonRequest)
		{
			var client = new HttpClient();
			var url = BaseUrl + "/savePerson?";
			url += "person=" + Uri.EscapeUriString(_person.ToString()) + "&";
		
			var content = new StringContent(savePersonRequest.ToJson());
			var response = await client.PostAsync(url, content);
			var data = await response.Content.ReadAsStringAsync(); 
			return SavePersonResponse.FromJson(data);
		}
		
		public async Task<Person> SavePerson3Async(Person person)
		{
			var client = new HttpClient();
			var url = BaseUrl + "/savePerson?";
			
		
			var content = new StringContent(person.ToJson());
			var response = await client.PostAsync(url, content);
			var data = await response.Content.ReadAsStringAsync(); 
			return Person.FromJson(data);
		}
		
		public async Task<long> GetSavePerson2Async(long _person)
		{
			var client = new HttpClient();
			var url = BaseUrl + "/savePerson2?";
			url += "person=" + Uri.EscapeUriString(_person.ToString()) + "&";
		
			var response = await client.GetAsync(url);
			var data = await response.Content.ReadAsStringAsync(); 
			return long.Parse(data);
		}
		
		public async Task<long> GetBlaAsync(string _long, string _lat)
		{
			var client = new HttpClient();
			var url = BaseUrl + "/overview?";
			url += "long=" + Uri.EscapeUriString(_long.ToString()) + "&";
			url += "lat=" + Uri.EscapeUriString(_lat.ToString()) + "&";
		
			var response = await client.GetAsync(url);
			var data = await response.Content.ReadAsStringAsync(); 
			return long.Parse(data);
		}
		
		public async Task<Overview> GetOverviewAsync(string _long, string _lat)
		{
			var client = new HttpClient();
			var url = BaseUrl + "/overview?";
			url += "long=" + Uri.EscapeUriString(_long.ToString()) + "&";
			url += "lat=" + Uri.EscapeUriString(_lat.ToString()) + "&";
		
			var response = await client.GetAsync(url);
			var data = await response.Content.ReadAsStringAsync(); 
			return Overview.FromJson(data);
		}
		
		
		
	}
	
	

}